/*
 * Copyright 2009 XueSong Guo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.webwheel;

/**
 * WebWheel MVC框架中动作类执行结果的解释器。<br>
 * 使用{@link cn.webwheel.Main#registerResultType(Class, ResultInterpreter)} 方法将此类的实现注册到框架中，
 * 以获得对某种结果类型的解释权。
 */
public interface ResultInterpreter<T> {

    /**
     * 初始化方法。
     * @throws Exception 初始化异常
     */
    void init() throws Exception;

    /**
     * 对结果对象进行解释。
     * @param result 结果对象，由{@link Action#execute()}返回
     * @param ctx 当前应用程序的上下文
     * @param action 返回此结果对象的动作类实例
     * @throws Exception 任何异常
     * @return 是否处理了此次http请求
     */
    boolean render(T result, WebContext ctx, Action action) throws Exception;

    /**
     * 销毁方法。
     */
    void destroy();
}
